package com.imay.live.view.custom;

import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.imay.live.helper.NumberHelper;
import com.imay.live.R;

/**
 * Created by Administrator on 2017/04/17 0017.
 */

public class RechargeTitle extends LinearLayout {
    TextView tv_content;
    TextView tv_title;

    public RechargeTitle(Context context) {
        super(context);
        init(context);
    }

    public RechargeTitle(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
        init(context);
    }

    public RechargeTitle(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @RequiresApi(api = 21)
    public RechargeTitle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    void init(Context context) {
        setOrientation(VERTICAL);
        tv_title = new TextView(context);
        tv_title.setText(getResources().getString(R.string.recharge_m));
        tv_title.setTextColor(getResources().getColor(R.color.bg_window));
        LayoutParams paramst = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        paramst.topMargin = (int) getResources().getDimension(R.dimen.title_top);
        paramst.bottomMargin = (int) getResources().getDimension(R.dimen.title_bottom);
        tv_title.setGravity(Gravity.CENTER);
        tv_title.setTextSize(16);
        addView(tv_title, paramst);
        tv_content = new TextView(context);
        tv_content.setGravity(Gravity.CENTER);
        tv_content.setTextColor(getResources().getColor(R.color.bg_window));
//        tv_content.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
        tv_content.setTextSize(51);
        tv_content.setSingleLine();
        tv_content.setEllipsize(TextUtils.TruncateAt.END);
        LayoutParams paramsc = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        paramsc.bottomMargin = (int) getResources().getDimension(R.dimen.title_top);
        paramsc.rightMargin = (int) getResources().getDimension(R.dimen.title_top);
        paramsc.leftMargin = (int) getResources().getDimension(R.dimen.title_top);
        addView(tv_content, paramsc);
    }

    public void setText(long meili) {
        if (meili<=0){
            tv_content.setText("0");
        }else {
            tv_content.setText(String.valueOf(meili));
        }

    }

    public void setTitleText(CharSequence text) {
        tv_title.setText(text);
    }
}
